﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using NASA.BeAMartian.Controls;
using Microsoft.Phone.Tasks;
using System.Windows.Navigation;

namespace NASA.BeAMartian.Views
{
    public partial class MapRoom : PhoneApplicationPage
    {
        public MapRoom()
        {
            InitializeComponent();
        }

        private void ImageButton_Click(object sender, RoutedEventArgs e)
        {
            ImageButton ib = sender as ImageButton;
            MediaPlayerLauncher mediaPlayerLauncher = new MediaPlayerLauncher()
            {
                Media = new Uri(ib.Tag.ToString(), UriKind.Absolute)
            };

            mediaPlayerLauncher.Show();
        }

        private void Image_ImageOpened(object sender, RoutedEventArgs e)
        {
            pbIntro.IsIndeterminate = false;
            pbIntro.Visibility = System.Windows.Visibility.Collapsed;
            (Resources["sbFadeInIntro"] as Storyboard).Begin();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            RemoveTask();

            if(NavigationContext.QueryString.ContainsKey("x"))
                pvt.SelectedIndex = int.Parse(NavigationContext.QueryString["x"]);

            base.OnNavigatedTo(e);
        }

        public void AddTask(Control task)
        {
            pvt.Visibility = System.Windows.Visibility.Collapsed;
            grdTaskContainer.Children.Clear();
            grdTaskContainer.Children.Add(task);
            grdTaskContainer.Visibility = System.Windows.Visibility.Visible;
        }

        public void RemoveTask()
        {
            pvt.Visibility = System.Windows.Visibility.Visible;
            grdTaskContainer.Children.Clear();
            grdTaskContainer.Visibility = System.Windows.Visibility.Collapsed;
        }
    }
}
